﻿using DataAccessLayer;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;

namespace BussinessLogicLayer
{
    public class BLL_Test_Section
    {
        public static List<TEST_SECTION_CUSTOM> Load(TEST test)
        {
            var list = new List<TEST_SECTION_CUSTOM>();
            DataTable dt = DAO_Test_Section.Load(test);
            if (dt != null && dt.Rows.Count > 0)
            {
                foreach (DataRow row in dt.Rows)
                {
                    list.Add(new TEST_SECTION_CUSTOM
                    {
                        TEST_SECTION_ID = Convert.ToDecimal(row["TEST_SECTION_ID"]),
                        TEST_SECTION_DESC = row["TEST_SECTION_DESC"].ToString(),
                        NUM_QUESTION = Convert.ToInt32(row["NUM_QUESTION"])
                    });
                }
            }

            return list;
        }

        public static List<TEST_SECTION_CUSTOM> Get(TEST test)
        {
            var list = new List<TEST_SECTION_CUSTOM>();
            DataTable dt = DAO_Test_Section.Get(test);
            if (dt != null && dt.Rows.Count > 0)
            {
                foreach (DataRow row in dt.Rows)
                {
                    list.Add(new TEST_SECTION_CUSTOM
                    {
                        TEST_SECTION_ID = Convert.ToDecimal(row["TEST_SECTION_ID"]),
                        TEST_SECTION_DESC = row["TEST_SECTION_DESC"].ToString(),
                        NUM_QUESTION = Convert.ToInt32(row["NUM_QUESTION"])
                    });
                }
            }

            return list;
        }

        public static TEST_SECTION GetTestSection(decimal testSection_ID)
        {
            var testSection = new TEST_SECTION();
            DataTable dt = DAO_Test_Section.GetTestSection(testSection_ID);
            if (dt != null && dt.Rows.Count > 0)
            {
                testSection.TEST_ID = Convert.ToDecimal(dt.Rows[0]["TEST_ID"]);
                testSection.TEST_SECTION_ID = Convert.ToDecimal(dt.Rows[0]["TEST_SECTION_ID"]);
                testSection.TEST_SECTION_DESC = dt.Rows[0]["TEST_SECTION_DESC"] == DBNull.Value ? "" : dt.Rows[0]["TEST_SECTION_DESC"].ToString();
            }

            return testSection;
        }

        public static List<QUESTION> GetQuestions(decimal testSection_ID)
        {
            var list = new List<QUESTION>();
            DataTable dt = DAO_Test_Section.GetQuestions(testSection_ID);
            if (dt != null && dt.Rows.Count > 0)
            {
                foreach (DataRow row in dt.Rows)
                {
                    list.Add(new QUESTION
                    {
                        QUESTION_ID = Convert.ToInt32(row["QUESTION_ID"]),
                        USER_ID = row["USER_ID"].ToString(),
                        QUESTION_DESCRIPTION = row["QUESTION_DESCRIPTION"] == DBNull.Value ? "" : row["QUESTION_DESCRIPTION"].ToString(),
                        QUESTION_LEVEL = row["QUESTION_LEVEL"].ToString(),
                        QUESTION_TYPE = row["QUESTION_TYPE"].ToString()
                    });
                }
            }

            return list;
        }

        public static List<QUESTION_CUSTOM> GetTestSectionQuestions(decimal testSection_ID)
        {
            var list = new List<QUESTION_CUSTOM>();
            DataTable dt = DAO_Test_Section.GetTestSectionQuestions(testSection_ID);
            if (dt != null && dt.Rows.Count > 0)
            {
                foreach (DataRow row in dt.Rows)
                {
                    list.Add(new QUESTION_CUSTOM
                    {
                        QUESTION_ID = Convert.ToInt32(row["QUESTION_ID"]),
                        QUESTION_DESCRIPTION = row["QUESTION_DESCRIPTION"] == DBNull.Value ? "" : row["QUESTION_DESCRIPTION"].ToString(),
                        QUESTION_TYPE = row["QUESTION_TYPE"].ToString(),
                        ITEM_ID = Convert.ToDecimal(row["ITEM_ID"]),
                        ITEM_FACE = row["ITEM_FACE"].ToString(),
                        FIGURE_PATH = row["FIGURE_PATH"] == DBNull.Value ? "" : row["FIGURE_PATH"].ToString()
                    });
                }
            }

            return list;
        }

        public static List<QUESTION_CUSTOM> GetTestSectionQuestionIDs(string questionIDs)
        {
            var list = new List<QUESTION_CUSTOM>();
            DataTable dt = DAO_Test_Section.GetTestSectionQuestionIDs(questionIDs);
            if (dt != null && dt.Rows.Count > 0)
            {
                foreach (DataRow row in dt.Rows)
                {
                    list.Add(new QUESTION_CUSTOM
                    {
                        QUESTION_ID = Convert.ToInt32(row["QUESTION_ID"]),
                        QUESTION_DESCRIPTION = row["QUESTION_DESCRIPTION"] == DBNull.Value ? "" : row["QUESTION_DESCRIPTION"].ToString(),
                        QUESTION_TYPE = row["QUESTION_TYPE"].ToString(),
                        ITEM_ID = Convert.ToDecimal(row["ITEM_ID"]),
                        ITEM_FACE = row["ITEM_FACE"].ToString(),
                        FIGURE_PATH = row["FIGURE_PATH"] == DBNull.Value ? "" : row["FIGURE_PATH"].ToString()
                    });
                }
            }

            return list;
        }
    }
}
